export function method1() {
  // ...
  method2("www");
}
 
export function method2() {
    console.log(222)

}

export function toast(msg, duration = 1500){
	
	uni.showToast({
	      title: msg,
	      icon: 'success',
	      duration: duration
	    });
}

export function toastwarn(msg,  duration = 1500){
	
	uni.showToast({
	      title: msg,
	      icon: 'error',
	      duration: duration
	    });
}

export function previewImage(picurl,index){
	uni.previewImage({
				urls: picurl,
				longPressActions: {
					itemList: ['发送给朋友', '保存图片', '收藏'],
					success: function(data) {
						console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
					},
					fail: function(err) {
						console.log(err.errMsg);
					}
				},
				current:index
			});
}


export function albumClass(index){
	if (index == 0) {
		return 'pic1thborder';
	}
	if (index == 2) {
		return 'pic3thborder';
	}
	return '';
}

export function uploadFiles(filelist,precenter){
	const asyncTasks = [];
	const picpath = [];
	const complete = 0;
	this.precenter = 90;
	for (let i = 0; i < filelist.length; i++) {
	  const asyncTask = uploadFile(filelist[i].url);
	  asyncTasks.push(asyncTask);
	}
	
	return asyncTasks;
	
}


//返回promoise
export function uploadFile(path){
	 return uniCloud.uploadFile({
		filePath: path,
		cloudPath: '1.jpg'
	})
}

export function addcomment(para){
	return uniCloud.callFunction({
		name: "addcomment",
		data: {
			"artileid":para.artileid,
			"content": para.content,
			"publishuser":para.publishuser,
			"publishuserid":para.publishuserid,
			"createteime":Date.now()
		}
	})
	
}

export function addpublish(para){
	return uniCloud.callFunction({
		name: "addpublish",
		data: {
			"userid":para.userid,
			"content": para.content,
			"recordtime":para.recordtime,
			"createtime":Date.now(),
			"url":para.url,
			type:para.type,
			username:para.username
		}
	})
	
}

export function editpublish(para){
	return uniCloud.callFunction({
		name:"updatepublish",
		data:{
			"content": para.content,
			"recordtime":para.recordtime,
			"url":para.url,
			"id":para.id
		}
	})
}

export function getList(para){
	return  uniCloud.callFunction({
		name: "getPublish",
		data: {
			"pageIndex":para.pageIndex,
		}
	})
	
}

export function getListById(id){
	return  uniCloud.callFunction({
		name: "getPublishById",
		data: {
			"id":id,
		}
	})
	
}

export function getComment(para){
	return  uniCloud.callFunction({
		name: "getComment",
		data: {
			"pid":para,
		}
	})
	
}


 export  function formatDate(date) {
  const year = date.getFullYear();
  const month = (date.getMonth() + 1).toString().padStart(2, '0');
  const day = date.getDate().toString().padStart(2, '0');
  return `${year}年${month}月${day}日`;
}

export  function formatDateyyymmdd(date) {
  const year = date.getFullYear();
  const month = (date.getMonth() + 1).toString().padStart(2, '0');
  const day = date.getDate().toString().padStart(2, '0');
  return `${year}-${month}-${day}`;
}

export function islogin(){
	try{
		const value = uni.getStorageSync('token');
		if(value){
			return true;
		}
	}catch(e){
		console.log(e);
	}
	return false;
}

export function getLoginInfo(){
	return {
		id:uni.getStorageSync('token'),
		username:uni.getStorageSync('username')
	};
}


export function addorupdate(para){
	console.log(para);
	return  uniCloud.callFunction({
		name: "adduser",
		data: {
			"name":para.name,
			"openid":para.openid
		}
	})
}

export function show(){
	const now = Date.parse(new Date());
	const delinetime = Date.parse('2024-11-08');
	return now>=delinetime;
	
}
